home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / nwtp06 / s_hello.pas < prev    next >
Pascal/Delphi Source File  |  1996-07-10  |  2KB  |  76 lines

  1. {$X+,B-,V-}
  2. program SendHello;
  3.  
  4. { Simple IPX demonstration program. Run this program on 1 workstation,
  5.   run R_HELLO on another. R_HELLO will receive the "hello world" messages
  6.   that this program sends.
  7.  
  8.   Polls the ECB until a packet is sent. No ESR used.   }
  9.  
  10. uses crt,nwMisc,nwIPX;
  11.  
  12. CONST IOSocket=$5678;
  13.  
  14. Var SendEcb:Tecb;
  15.     IpxHdr:TipxHeader;
  16.     socket:word;
  17.     dest:TinternetworkAddress;
  18.     buf:array[1..546] of byte;
  19.     t:byte;
  20.     w:word;
  21.     s:string;
  22. begin
  23. IF NOT IpxInitialize
  24.  then begin
  25.       writeln('Ipx needs to be installed.');
  26.       halt(1);
  27.       end;
  28. socket:=IOSocket;
  29. IF NOT IPXopenSocket(Socket,SHORT_LIVED_SOCKET)
  30.  then begin
  31.       writeln('IPXopenSocket returned error# ',nwIPX.result);
  32.       halt(1);
  33.       end;
  34.  
  35. for t:=1 to 4 do dest.net[t]:=$00; { this net / segment }
  36. for t:=1 to 6 do dest.node[t]:=$FF; { all nodes }
  37. dest.socket:=IOsocket;
  38. w:=0;
  39.  
  40. Repeat
  41.   inc (w);
  42.  
  43.   { Fill buffer (ECB.fragment[2]^) }
  44.   str(w:4,s);
  45.   s:=s+' IPX: Hello World';
  46.   FillChar(buf,546,#0);
  47.   move(s[1],buf,ord(s[0]));
  48.  
  49.   { setup ECB and IPX header }
  50.   IPXsetupSendECB(NIL,IOsocket,dest,@buf,ord(s[0]),
  51.                   IpxHdr,SendEcb);
  52.   IPXsendPacket(SendEcb);
  53.  
  54.   { Poll the Inuse Flag until the packet is sent. }
  55.   While SendEcb.InUseFlag<>0
  56.    do IPXrelinquishControl;
  57.  
  58.   { ECB.InUseFlag was lowered, now determine if packet was sent: }
  59.   CASE SendEcb.CompletionCode OF
  60.    $00:writeln('IPX packet #',w:0,' was sent.');
  61.    $FC:writeln('The send of packet #',w:0,' was canceled.');
  62.        { impossible, as this cancelation to be done by THIS program, and it doesn't }
  63.    $FD:writeln('Packet# ',w:0,' is malformed and was not sent.');
  64.        { illegal param: packet length, number of fragments, fragment size. }
  65.    $FE:writeln('Packet# ',w:0,' was undelivered. No stations listening.');
  66.    $FF:writeln('Packet# ',w:0,' not sent due to a hardware error.');
  67.   end;
  68.  
  69.   { Wait 5 seconds between sending packets }
  70.   delay(5000);
  71. UNTIL keypressed;
  72.  
  73. IF NOT IPXcloseSocket(IOsocket)
  74. then writeln('IPXcloseSocket returned error# ',nwIPX.result);
  75.  
  76. end.